package util;

import annotation.Check;
import dao.AddpowerDao;
import dao.impl.AddpowerDaoImpl;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Method;

public class TestCheck {
    public static void main(String[] args) throws IOException {
        AddpowerDao c = new AddpowerDaoImpl();
        Class cls = c.getClass();
        Method[] methods = cls.getDeclaredMethods();
        BufferedWriter bw = new BufferedWriter(new FileWriter("/property/addpowerBug.txt"));
        for (Method method : methods) {
            if (method.isAnnotationPresent(Check.class)) {
                try {
                    method.invoke(c);
                } catch (Exception e) {
                    bw.write(method.getName() + "方法出现异常");
                    bw.newLine();
                    bw.write("名称：" + e.getCause().getClass().getSimpleName());
                    bw.newLine();
                    bw.write("原因：" + e.getCause().getMessage());
                    bw.newLine();
                    bw.write("-------------------");
                    bw.newLine();
                }
            }
        }
        bw.flush();
        bw.close();
    }
}
